package com.cxg.fairy.ui.recycler.HorizontalListView;

import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cxg.fairy.ui.R;


/**
 * Created by Administrator on 2018/3/2.
 */

public class HorizontalListAdapter extends ArrayAdapter<OrderListHorizontalImageData>{

    private LayoutInflater mInflater;

    private AppCompatImageView orderHorImageView = null;

    public HorizontalListAdapter(Context context, OrderListHorizontalImageData[] values) {
        super(context, R.layout.item_order_horizontal_image, values);
        mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;

        if (convertView == null) {
            // Inflate the view since it does not exist
            convertView = mInflater.inflate(R.layout.item_order_horizontal_image, parent, false);

            // Create and save off the holder in the tag so we get quick access to inner fields
            // This must be done for performance reasons
            holder = new Holder();
            holder.textView = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        // Populate the text
        holder.textView.setText(getItem(position).getText());

        orderHorImageView = (AppCompatImageView) convertView.findViewById(R.id.order_hor_aiv_id);

        Glide.with(convertView.getContext()).load(getItem(position).getImgUrl()).into(orderHorImageView);

//        convertView.setBackgroundColor(getItem(position).getBackgroundColor());

        return convertView;
    }

    /** View holder for the views we need access to */
    private static class Holder {
        public TextView textView;
    }


}
